package com.vishop.services;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.vishop.daos.BestellingDaoImpl;
import com.vishop.daos.PersoonDaoImpl;
import com.vishop.models.Bestelling;
import com.vishop.models.Persoon;

@Service
public class BestellingServiceImpl implements BestellingService {
 
    @Autowired
    private BestellingDaoImpl bestellingDao;
    
    @Autowired
    private PersoonDaoImpl persoonDao;
     
    
    @Transactional
    public int save(Bestelling bestelling){
    	int oudePunten;
    	int nieuwePunten;
    	
    	Persoon persoon = bestelling.getPersoon();
    	oudePunten = persoon.getPunten();
    	nieuwePunten = oudePunten + 10;
    	persoon.setPunten(nieuwePunten);
    	persoonDao.updatePunten(persoon);

   		return bestellingDao.save(bestelling);
   	}
    
    @Transactional
    public Bestelling getById(int id){
    	return bestellingDao.getById(id);
    }
    @Transactional
    public Collection<Bestelling> getAllBestelling(){
		return bestellingDao.getAllBestelling();
	}
    @Transactional
    public Collection<Bestelling> getAllBestellingByPersoon(){
		return bestellingDao.getAllBestellingByPersoon();
	}
    
    

}
